﻿using System;
using System.Collections.Generic;
using System.Text;
using Consul;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace MicroContainers.AspCore.Consul.ServiceDiscovery
{
    public static class ServiceDiscoveryExtensions
    {
        public static IServiceCollection AddConsulServiceDiscovery(this IServiceCollection services)
        {
            services.AddSingleton<IServiceDiscovery, ServiceDiscovery>();

            return services;
        }

        public static IApplicationBuilder UseConsulServiceDiscovery(this IApplicationBuilder app,
            Action<ServiceDiscoveryConfig> configAction)
        {
            var serviceDiscovery = app.ApplicationServices.GetRequiredService<IServiceDiscovery>();

            serviceDiscovery.Config(configAction);

            return app;
        }
    }
}
